package com.online.service_edu.controller;


import com.online.common_utils.ResultJson;
import com.online.service_edu.entity.vo.CourseInfo;
import com.online.service_edu.service.EduCourseService;
import com.online.service_edu.service.EduSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author hdc2008
 * @since 2021-02-11
 */
@RestController
@RequestMapping("/service_edu/course")
@CrossOrigin
public class EduCourseController {

    @Autowired
    private EduCourseService eduCourseService;

    @PostMapping("addCourse")
    public ResultJson addCourse(@RequestBody CourseInfo courseInfo){
        String courseId=eduCourseService.addCourseInfo(courseInfo);

        return ResultJson.ok().data("cId",courseId);
    }

    @GetMapping("courseInfo/{id}")
    public ResultJson getCourseInfoById(@PathVariable String id){
       CourseInfo courseInfo=eduCourseService.getCourseInfo(id);
        return ResultJson.ok().data("courseInfo",courseInfo);
    }

    @PostMapping("updateCourse")
    public ResultJson updateCourse(@RequestBody CourseInfo courseInfo){
        eduCourseService.updateCourseInfo(courseInfo);

        return ResultJson.ok();
    }

    @DeleteMapping("delete/{id}")
    public ResultJson deleteCourseById(@PathVariable String id){
        boolean flag=eduCourseService.removeCourseById(id);
        if(flag){
            return ResultJson.ok();
        }else{
            return ResultJson.error().message("请删除完小节，才能删除章");
        }
    }

}

